home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1990 / number5 / msg_pckt.hpp < prev    next >
C/C++ Source or Header  |  1990-10-06  |  3KB  |  83 lines

  1. /**************************************************************************
  2. *   MSG_PCKT.HPP - Listing 5
  3. *   Written by Kevin D. Weeks, August 1990
  4. *   Compiles and runs under Borland Turbo C++ and Zortech C++.
  5. */
  6. #if !defined(MSG_PCKT_HPP)
  7. #define MSG_PCKT_HPP
  8. #include "serial.hpp"
  9. // the following types are used to control file transfer between two
  10. // devices.
  11. enum Msg_Type
  12. {
  13.     NO_MESSAGE,         // used only as a response to get_msg_type()
  14.     END_OF_PROCESS,     // designates end of load data or file process
  15.     PROGRAM_INQUIRE,    // requests list of programs for upload
  16.     LOAD_PROGRAM,       // requests that a program be uploaded
  17.     DATA_INQUIRE,       // requests list of data files
  18.     DATA_UPLOAD,        // requests that a data file be uploaded
  19.     DATA_DOWNLOAD,      // requests that a data file be downloaded
  20.     MSG_ERROR           // general error
  21. };
  22. // this structure is used to monitor internal object status
  23. struct Msg_Status
  24. {
  25.     unsigned int    type_read : 1;
  26.     unsigned int    size_read : 1;
  27.     unsigned int    msg_read : 1;
  28. };
  29. struct Msg_Buffer
  30. {
  31.     Msg_Type        type;
  32.     int             length;
  33.     unsigned char   msg[1026];
  34. };
  35. class Msg_Packet : public Serial_Comm
  36. {
  37.   public:
  38.     // constructors and destructor
  39.             Msg_Packet(void);
  40.             Msg_Packet(Com_Port port, Baud_Rate baud, Parity par,
  41.                        Stop_Bits stop, Data_Bits data);
  42.             ~Msg_Packet(void) {};
  43.     // these methods provide support for the packet parameters. Note
  44.     // that the original read() and write() methods in Serial_Comm
  45.     // are still accessable.
  46.     Result      read(Msg_Type *type, int *msg_size, void *buffer);
  47.     Result      write(Msg_Type type, int msg_size, void *buffer);
  48.     // the following methods replace their originals in Serial_Comm
  49.     void        clr_recv_buffer(void);
  50.     void        clr_send_buffer(void);
  51.     // these methods are non-destructive (unlike the read() method).
  52.     // in effect they allow the user to peek at what's in the buffer
  53.     // without committing.
  54.     Msg_Type    get_recv_msg_type(void);
  55.     int         get_recv_msg_size(void);
  56.     Result      get_recv_message(void *buffer);
  57.     // the next three methods are also non-committal. nothing is
  58.     // actually sent until send_message() is called.
  59.     void        set_send_msg_type(Msg_Type type)
  60.                 { send_msg_buffer.type = type; };
  61.     Result      set_send_msg_size(int size);
  62.     void        set_send_message(void *buffer)
  63.               {memcpy(send_msg_buffer.msg,buffer,get_buffer_size());};
  64.     Result      send_message(void);
  65.     int         get_timeout(void) { return timeout; };
  66.     int         get_retrys(void) { return re_trys; };
  67.     void        set_timeout(int tenths) { timeout = tenths; };
  68.     void        set_retrys(int num_trys) { re_trys = num_trys; };
  69.     // these three methods disable the base class' methods.
  70.     // buffer_size is hard coded and input and output MUST take place
  71.     // through the read() and write() methods above.
  72.     Result      set_buffer_size(void) { return ERROR; };
  73.     int         read_char(void) { return ERROR; };
  74.     Result      write_char(void) { return ERROR; };
  75.   private:
  76.     Msg_Status      status;
  77.     int             timeout;
  78.     int             re_trys;
  79.     Msg_Buffer      recv_msg_buffer;
  80.     Msg_Buffer      send_msg_buffer;
  81. };
  82. #endif
  83.